<template>
	<div class="discount-hb">
		<ul class="discount-list">
			<li class="discount-item">
				<div class="discount-xinxi">
					<h3 v-text="item.coupon_name"></h3>
					<span>满</span><span v-text="item.min_amount>0?item.min_amount:'无门槛'"></span><span>使用</span>
					<p>使用期限 <span v-text="new Date(Number(item.start_time)*1000).Format('yyyy.MM.dd')"></span>-<span v-text="new Date(Number(item.end_time)*1000).Format('yyyy.MM.dd')"></span></p>
				</div>
				<div class="discount-jine">
					<h3 v-html="'<span>￥</span>'+item.coupon_value"></h3>
					<span v-text="(item.type==1&&item.store_id==0)?'平台红包':'优惠券'"></span>
				</div>
			</li>
		</ul>
		<p class="btn_lingqu lijq-btn" v-if="item.use_times>0&&item.already==0" @click="lqyhq()">立即领取</p>
		<p class="btn_lingqu ljsy-btn" v-if="item.use_times>0&&item.already==1" @click="yhqtiao()">立即使用</p>
		<p class="btn_lingqu wfsy-btn" v-if="item.use_times==0">已使用</p>
	</div>
</template>

<script>
	export default{
		data () {
			return{
				user:0,
				yhid:0,
				youhuishow:true,
				item:'',
				coupon_sn:0
			}
		},
		created:function(){
			if(localStorage.getItem("nt_user")){
				this.user=localStorage.getItem("nt_user");
			}else{
				this.$router.push({path:'/login'});
			}
			if(this.$route.query.id){
				this.yhid=this.$route.query.id;
			}
			if(this.$route.query.coupon_sn){
				this.coupon_sn=this.$route.query.coupon_sn;
			}
		},
		mounted:function(){
			var self=this;
			$.ajax({
				type:"get",
				url:furl+"index.php?app=ajax_coupon&act=coupon_dst_view",
				data:{'id':self.yhid,'token':self.user,'coupon_sn':self.coupon_sn},
				dataType:'json',
				success:function(res){
					if(res.done){
						self.item=res.retval;
					}else{
						self.youhuishow=false;
					}
				}
			});
		},
		methods:{
			lqyhq:function(){
				var self=this;
				$.ajax({
					type:"post",
					url:furl+"index.php?app=ajax_coupon&act=coupon_dst_add",
					data:{'token':self.user,'coupon_id':self.yhid,'coupon_sn':self.coupon_sn},
					dataType:'json',
					success:function(res){
						if(res.done){
							self.item.already=1;
						}
					}
				});
			},
			yhqtiao:function(){
				if(this.item.type==1&&this.item.store_id==0){
					this.$router.push({path:'taqing'});
				}else if(this.item.goods_only==0){
					this.$router.push({path:'/business/shopindex',query:{'store':this.item.store_id}});
				}else{
					this.$router.push({name:'shopXQ',params:{id:this.item.goods_id}});
				}
				
			}
		}
	}
</script>

<style>
	.discount-hb{font-size:0;}
	.discount-list{padding-left:0.27rem;padding-right:0.27rem;padding-top: 0.38rem;}
	.discount-item{background-image:url(../../img-discount/hbbg.png);background-repeat:no-repeat;background-size:100%;position:relative;margin-bottom: 0.16rem;}
	.discount-sy{position:absolute;top:-0.11rem;right:-0.12rem;width:1.1rem;height:0.84rem;}
	.discount-xinxi{display:inline-block;width:4.5rem;height:2.25rem;box-sizing: border-box;padding: 0.4rem 0 0 0.4rem;}
	.discount-xinxi>h3{font-size:0.32rem;color:#2b2b2b;line-height: 0.3rem;margin-bottom: 0.24rem;}
	.discount-xinxi>span{display:inline-block;font-size:0.24rem;color:#4C9D31;line-height: 0.23rem;margin-bottom: 0.39rem;font-weight:600;}
	.discount-xinxi>p{font-size:0.22rem;color:#999;line-height: 0.22rem;}
	.discount-jine{display: inline-block;width:2.3rem;float:right;margin-right: 0.08rem;text-align: center;}
	.discount-jine>h3{font-size:0.5rem;color:#4c9d31;line-height: 0.6rem;margin-bottom: 0.1rem;margin-top: 0.54rem;font-weight:500;margin-right: 0.2rem;}
	.discount-jine>h3>span{font-size:0.4rem;}
	.discount-jine>span{font-size:0.24rem;color:#4C9D31;line-height: 0.24rem;}
	.diacount-shixiao h3,.diacount-shixiao span,.diacount-shixiao p{color:#999 !important;}
	.btn_lingqu{width:6.86rem;height:1rem;box-sizing: border-box;margin:0.3rem auto 0;font-size:0.36rem;text-align: center;line-height: 1rem;border-radius:0.5rem;color:#fff;
	}
	.lijq-btn{background-color:#6FC452;}
	.ljsy-btn{background-color:#6FC452;}
	.wfsy-btn{background-color:#8DB87E;}
</style>